package com.hq.fxh.No1_Infromation.Infor.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.hq.fxh.R;
import com.hq.fxh.Utils.LogUtils;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created ${data}
 * @Email xlwenhao1858@sina.com
 */

public class Help_Infor_GridView {
    Context context;
    GridView gridView;
    Adapter_recycle_infor.GridViewHolder holder;
    String[] names = {"房产", "汽车", "招聘", "二手", "家政", "餐饮", "娱乐", "更多"};
    int[] icons = {R.mipmap.shouye_fangchan, R.mipmap.shouye_qiche, R.mipmap.shouye_zhaopin, R.mipmap.shouye_ershou,
            R.mipmap.shouye_jiazheng, R.mipmap.shouye_canyin, R.mipmap.shouye_yule, R.mipmap.shouye_gengduo,};

    public Help_Infor_GridView(Context context, GridView gridView) {
        this.gridView = gridView;
        this.context = context;
        doForGridView();
    }

    public void doForGridView() {
        gridviewAdapter adapter = new gridviewAdapter();
        gridView.setAdapter(adapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                LogUtils.e("分类选择框" + i);
            }
        });
    }

    private class gridviewAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return names.length;
        }

        @Override
        public Object getItem(int i) {
            return names[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View convertView, ViewGroup parent) {
            View view = convertView;
            ViewHolder viewHolder = null;
            if (view == null || !(view.getTag() instanceof ViewHolder)) {
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_tab, null);
                viewHolder = new ViewHolder(view);
                view.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) view.getTag();
            }
            viewHolder.imgTitle.setImageResource(icons[i]);
            viewHolder.txtTitle.setText(names[i]);
            return view;
        }

        private class ViewHolder {
            protected ImageView imgTitle;
            protected TextView txtTitle;

            ViewHolder(View rootView) {
                initView(rootView);
            }

            private void initView(View rootView) {
                imgTitle = (ImageView) rootView.findViewById(R.id.img_title);
                txtTitle = (TextView) rootView.findViewById(R.id.txt_title);
                ViewGroup.LayoutParams layoutParams = imgTitle.getLayoutParams();
                layoutParams.height = 70;
                layoutParams.width = 70;
                imgTitle.setLayoutParams(layoutParams);
                txtTitle.setTextSize(13);
                txtTitle.setPadding(0, 10, 0, 0);
            }
        }
    }
}
